/*-------------------------------------------------------------------------
   Copyright (C) 2010 One Laptop per Child

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!

   As a special exception, you may use this file as part of a free software
   library for the XO of the One Laptop per Child project without restriction.
   Specifically, if other files instantiate
   templates or use macros or inline functions from this file, or you compile
   this file and link it with other files to produce an executable, this
   file does not by itself cause the resulting executable to be covered by
   the GNU General Public License.  This exception does not however
   invalidate any other reasons why the executable file might be covered by
   the GNU General Public License.
-------------------------------------------------------------------------*/
#ifndef SDI_H
#define SDI_H

// Zero is unused.  When you clock in bytes from a command
// response zeros are clocked in so they need to be
// skipped.
#define SDI_CHANNEL_SWITCH	1
#define SDI_CHANNEL_CMDRESP	2
#define SDI_CHANNEL_KEYBOARD	3
#define SDI_CHANNEL_TOUCHPAD	4
#define SDI_CHANNEL_EVENT	5
#define SDI_CHANNEL_DEBUG	6
#define SDI_CHANNEL_CMDERROR	7

void intsrv_sdi(void) EXTERN_INTERRUPT(30);

void sdi_set_debug(char bits);

void sdi_module_init(void);
void sdi_init(void);
void sdi_deinit(void);
void sdi_start(void);
void sdi_process(void);
void sdi_up_queue_clear(void);

unsigned char sdi_up_queue_ready(void);

int sdi_up_queue_add(unsigned char dest, unsigned char val);

int sdi_cmdresp_queue_add(unsigned char val);
int sdi_cmdresp_queue_get(void);

extern unsigned char xdata sdi_cmdresp_error;

extern unsigned char xdata sdi_command_packet[];
#define SDI_CMD_ARG(n) sdi_command_packet[(n) + 3]
#define SDI_CMD_ARGS sdi_command_packet[1]

#endif
